-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refs #10692 - added command-line option --cpp-header-probe
to probe headers and extension-less files for Emacs C++ marker
#6324
Conversation
Still work in progress... The standard library and LLVM are specifying this among others. Just running it on This will be disabled by default but I am considering enabling it by default in the release afterwards. Will also add a commit which adds it to our headers. Will most likely do it in a separate PR. |
Requires #6325 to be merged first. After #6211 has landed (if even possible) and we finally upgraded to PCRE2 (see https://trac.cppcheck.net/ticket/10610) we should replace most of the messy parsing code with a regular expression. |
What is the canonical use case for this? |
That is described in the ticket. It is mainly for IDE integrations. When you open a header by default it will be treated as C file and when it is actually C++ code it will error out. So you need to specify For the CLI usage this should not have any impact at all since the probing would only be performed if you explicitly pass a file with the This is based on the implementation of the CLion plugin which only has a single global configuration for the options being provided. On a side note it already helped to detect two issues hard to spot issues. 😀 |
Thanks for the explanation. IDEs were mentioned in the ticket, but I didn't make the connection to IDE integration. |
I just realized there is no upstream ticket for this. It is mentioned in the known issues though: https://github.com/johnthagen/clion-cppcheck?tab=readme-ov-file#analyzing-header-files. |
--cpp-probe
to probe headers and extension-less files for Emacs marker--cpp-header-probe
to probe headers and extension-less files for Emacs marker
I also encountered some performance issues with some headers even when I disable ValueFlow and all checks so it is probably related to the tokenizing or preprocessing. I have not looked into that yet. |
Turns out this only occurs in a debug build so there is no issue. |
--cpp-header-probe
to probe headers and extension-less files for Emacs marker--cpp-header-probe
to probe headers and extension-less files for Emacs C++ marker
36708cf
to
78807ce
Compare
To test this with existing headers I patched out some code for speed, enabled the logging in It seems this uncovered bad markers in the LLVM headers which I reported upstream: llvm/llvm-project#89965. |
--cpp-header-probe
to probe headers and extension-less files for Emacs C++ marker--cpp-header-probe
to probe headers and extension-less files for Emacs C++ marker
This does not currently handle markers in |
799b1aa
to
56f257d
Compare
0439266
to
3cc9090
Compare
lib/tokenize.cpp
Outdated
@@ -8052,7 +8052,8 @@ void Tokenizer::unmatchedToken(const Token *tok) const | |||
void Tokenizer::syntaxErrorC(const Token *tok, const std::string &what) const | |||
{ | |||
printDebugOutput(0); | |||
throw InternalError(tok, "Code '"+what+"' is invalid C code. Use --std or --language to configure the language.", InternalError::SYNTAX); | |||
// TODO | |||
throw InternalError(tok, "Code '"+what+"' is invalid C code.\nUse --std or --language to configure the language or --cpp-header-probe to detect C++ headers via the Emacs marker.", InternalError::SYNTAX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This obviously needs to be reworded but I couldn't come up with something better yet.
I also moved the references to the options to the verbose part of the message. That should be done for a lot more messages but will be tackled at a future date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already re-worded it before I made it ready for review.
findAndReplace(marker, "Mode:", ""); | ||
marker = trim(marker); | ||
if (marker == "C++" || marker == "c++") { | ||
// NOLINTNEXTLINE(readability-simplify-boolean-expr) - TODO: FP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upstream issue: llvm/llvm-project#93157.
… headers and extension-less files for Emacs C++ marker
No description provided.